class Dictionary (object):
	def __init__(self):
		self.dic = {}
		self.counter = 0

	def add_word (self, key, value):
		if self.dic.has_key (key):
			print "La palabra ya existe en el diccionario"
		else:
			self.dic[key] = value
			self.counter = self.counter + 1
			print "La palabra se ha agregado con exito"

	def search_word (self, key):
		if self.dic.has_key (key):
			value = self.dic[key]
			print "La definicion es: %s" %value
		else:
			print "La palabra no existe en el diccionario"

	def change_definition (self, key, new_value):
		if self.dic.has_key (key):
			self.dic[key] = new_value
			print "La palabra se ha modificado con exito"
		else:
			print "La palabra no existe en el diccionario"

	def print_dictionary (self):
		keys = self.dic.keys ()
		for k in keys:
			print "%s : %s" % (k,self.dic[k])

	def print_dictionary_lenght (self):
		return self.counter

	def delete_word (self, key):
		if self.dic.has_key (key):
			self.dic.pop(key)
			self.counter = self.counter - 1
			print "La palabra se ha eliminado con exito"
		else:
			print "La palabra no existe en el diccionario"

	def read_dic_from_file (self, path):
		aux = open (path, 'r')
		while True:
			line = aux.readline ()
			if not line: break
			part_line = line.rpartition (':')
			self.dic[part_line[0]] = part_line[2]
			self.counter = self.counter + 1
		aux.close ()

	def write_dic_to_file (self, path):
		aux = open (path,'w')
		keys = self.dic.keys ()
		for k in keys:
			aux.write ("%s:%s \n" % (k,self.dic[k]))
